package com.songlanyun.modules.usergains.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;

import java.math.BigDecimal;
import java.io.Serializable;
import java.util.Date;

import com.songlanyun.common.drive.RootEntity;
import com.songlanyun.common.enums.BillConstant;
import com.songlanyun.common.enums.UserBillConstant;
import com.songlanyun.common.utils.custom.DateCustomUtils;
import lombok.Data;

/**
 * 会员分销所得账单
 *
 * @author wuchao
 * @email sunlightcs@gmail.com
 * @date 2020-12-22 15:21:52
 */
@Data
@TableName("yxt_distribution_user_bill")
public class UserBill extends RootEntity<Long, UserBill> implements Serializable {
    private static final long serialVersionUID = 1L;

    {
        createTimeMillis = System.currentTimeMillis();//当前时间戳
        outerMode = UserBillConstant.OuterMode.SPENDING;
        innerMode = UserBillConstant.InnerMode.SPENDING;
    }

    /**
     *
     */
    @TableId
    private Long id;
    /**
     * 会员id
     */
    private Long userId;
    /**
     * 所得帐单描述
     */
    private String remark;
    /**
     * 账单类型（0，支出（提现），1收入（结算分佣所得））
     */
    private UserBillConstant.BillType billType;
    /**
     * 收入模式：0、非收入，1分润所得
     */
    private UserBillConstant.InnerMode innerMode;
    /**
     * 支出模式：（0，非支出，1提现）
     */
    private UserBillConstant.OuterMode outerMode;

    @TableField(exist = false)
    private String mode;

    public String getMode() {
        if (UserBillConstant.BillType.EXPENDITURE == billType) {
            this.mode = outerMode.getMsg();
        } else {
            this.mode = innerMode.getMsg();
        }
        return this.mode;
    }

    /**
     * 入帐前的余额
     */
    private BigDecimal entryBefore;
    /**
     * 入帐后的余额
     */
    private BigDecimal entryAfter;
    /**
     * 入帐的额度
     */
    private BigDecimal entryValue;

    /**
     * 操作者
     */
    private String operator;
    /**
     * 入账时间
     */
    private Long createTimeMillis;
    public void  setCreateTimeMillis(Long createTimeMillis)
    {
        this.createTimeMillis= createTimeMillis;
        this.formatCreateTimeMillis = DateCustomUtils.formatToDateTimeString(createTimeMillis);
    }

    /**
     * 格式化创建时间
     */
    @TableField(exist =  false)
    private String formatCreateTimeMillis;

    /**
     * 单 号
     */
    private String code;

    @Override
    public Long getIdentity() {
        return id;
    }
}
